<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            width: 400px;
            height: 200px;
            margin: 0 auto;
        }
    </style>
</head>
<body>
    <div>
        <p>
            <input type="text" value="1,2,3">
            求数字之间的和，用逗号隔开
        </p>
        <button onclick="qh()">求和</button>
      <span></span>
    </div>
</body>
</html>
<script>

    function qh() {
        var span = document.querySelector('span')
        var value = document.querySelector('input').value.split(',')
        var sum = 0
        for(var i in value){
           sum += parseInt(value[i])
        }
        span.innerHTML = sum
    }
</script>